#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

void setPort(int fd)
{
	struct termios options;

//	fcntl(fd, F_SETFL, 0);
	fcntl(fd, F_SETFL, FNDELAY);     //Read without block
	tcgetattr(fd, &options);
	///*
	//Set the seriel
	cfsetispeed(&options, B38400);
	cfsetospeed(&options, B38400);
	options.c_cflag &= ~PARENB;		//No parity
	options.c_cflag &= ~CSTOPB;		//1 stop bit, otherwise 2
	options.c_cflag &= ~CSIZE;			//8bit data
	options.c_cflag |= CS8;
	options.c_cflag &= ~CRTSCTS;		//No hard ware flow control
	//*/

	// Enable the receiver and set local mode...
	options.c_cflag |= (CLOCAL | CREAD);
	options.c_lflag     &= ~(ICANON | ECHO | ECHOE);	//Not raw input, with echo
	options.c_oflag     &= ~OPOST;							//Not raw output

	//Set the new options for the port...
	tcsetattr(fd, TCSAFLUSH, &options);

}

/*
int main()
{
	int fd;
	fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
	if (fd == -1)
	{
	  printf("error");
	  return -1;
	}
	else
		fcntl(fd, F_SETFL, 0);
	setPort(fd);
	close(fd);
}
*/
